const { verifyToken } = require('../utils/token')

module.exports = (req, res, next) => {
  // 检验token
  let token = req.headers.authorization
  // 解析token
  let data = verifyToken(token)

  if (data === false) {
    // 校验token失效
    res.status(401).json({ msg: '用户访问token授权失败', code: 'A0230' })
  } else {
    // token成功
    req.admin_id = data.admin_id // 便于后面中间件去获取
    next()
  }
}
